package lee.android.dafuwon;

import lee.android.factory.ButtonFactory;
import lee.base.structure.BoundingBox;
import lee.base.structure.MyHashTree;
import lee.base.xml.ContentParser;
import lee.base.xml.XmlReader;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.util.DisplayMetrics;
import android.widget.AbsoluteLayout;

public class MainActivity extends Activity {

	String filePathRoot = null;
	MyHashTree treeLayoutInfo = null;
	ContentParser cp = null;
	
	int frameWidth = 0, frameHeight = 0;
	
	AbsoluteLayout mainLayout = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //initialize variable
        this._001_initialVariable();
        //read some necessary file
        this._002_readFile();
        //build component based on tree data
        this._003_buildFrameComponent();
    }
    
    private void _001_initialVariable() {
    	//set filePath
    	this.filePathRoot = Environment.getExternalStorageDirectory().toString();
    	//create ContentParser object
    	this.cp = new ContentParser();
    	//set width and length of screen
    	DisplayMetrics dm = new DisplayMetrics();
    	this.getWindowManager().getDefaultDisplay().getMetrics(dm);
    	this.frameWidth = dm.widthPixels;
    	this.frameHeight = dm.heightPixels;
    }
    
    private void _002_readFile() {
    	//get layout information for this frame
    	this.treeLayoutInfo = new XmlReader(this.filePathRoot + "/FrameMainMode1/Frame_GameMain.xml").GET001_MyHashTree();
    	//set initial value to tree parameter
    	this.treeLayoutInfo.ACT004_setSpecificValue("$ref1.width", this.frameWidth + "");
    	this.treeLayoutInfo.ACT004_setSpecificValue("$ref1.height", this.frameHeight + "");
    	//parse layout information tree
    	this.cp.ACT001_parseFullTree(this.treeLayoutInfo);
    }
    
    @SuppressWarnings("deprecation")
	private void _003_buildFrameComponent() {
    	//set layout
    	this.mainLayout = new AbsoluteLayout(this);
    	//test image button
    	this.mainLayout.addView(ButtonFactory.getImageButton(this.filePathRoot + "/FrameMainMode1/img_icon_throw_dice.png", this, new BoundingBox(0,150,200,100)));
    	//set view
    	this.setContentView(this.mainLayout);
    }
}
